home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* DATABOSS MODULE: DB_STR.C */
- /****************************************************************************/
-
- #include "db_lsc.h"
-
- #include <stdarg.h>
- #include <stddef.h>
- #include <string.h>
- #include "db_types.h"
- #include "db_str.h"
-
- /**************************** IMPLEMENTATION ******************************/
-
- /* new for 3.6 works exactly the same as sprintf see your compiler documentation
- except returns the string passed in. so it can be used in DataBoss Expressions
-
- Chris
- */
-
-
-
- char* DB_Sprintf( char* pachBuffer, char* pchFormat,...)
- {
- va_list ap;
- va_start(ap,pchFormat);
- vsprintf(pachBuffer,pchFormat,ap);
- return ( pachBuffer );
- }
-
-
- strptr strcopy(string sout, string s, int from, int len)
- {
- int slen;
-
- slen = strlen(s);
- if (from < slen) {
- if ((from + len) > slen) len = slen - from;
- memmove(sout,&s[from],len);
- sout[len] = '\0';
- }
- else
- sout[0] = '\0';
- return (sout);
- }
-
- strptr strconcat(string sout, ...)
- {
- va_list ap;
- string s;
- strptr dest,sarg;
-
- dest = s;
- va_start(ap,sout);
- while ((sarg = va_arg(ap,strptr)) != NULL) dest = stpcpy(dest,sarg);
- va_end(ap);
- *dest = '\0';
- return (strcpy(sout,s));
- }
-
- strptr strdelete(string s, int from, int len)
- {
- int slen;
-
- slen = strlen(s);
- if ((len != 0) && (from < slen))
- strcpy(&s[from],&s[((from + len) < slen) ? from + len : slen]);
- return (s);
- }
-
- strptr strinsert(string sins, string s, int pos)
- {
- int slen,ilen;
-
- slen = strlen(s);
- ilen = strlen(sins);
- if (ilen) {
- if (pos < slen) {
- memmove(&s[pos+ilen],&s[pos],slen-pos+1);
- memmove(&s[pos],sins,ilen);
- }
- else
- strcpy(&s[slen],sins);
- }
- return (s);
- }
-
- int strposstr(string chkfor, string s)
- {
- uchar huge *hp;
- uchar huge *hs;
-
- hs = s;
- hp = strstr(s, chkfor);
- return ((hp == NULL) ? -1 : (int) (hp - hs));
- }
-
- int strposch(uchar c, string s)
- {
- uchar huge *hp;
- uchar huge *hs;
-
- hs = s;
- hp = strchr(s,c);
- return ((hp == NULL) ? -1 : (int) (hp - hs));
- }
-
- strptr chstr(string sout, byte c)
- {
- *((word *) sout) = (word) c;
- return (sout);
- }
-
- strptr strchcat(strptr s, uchar ch)
- {
- strptr tp;
-
- tp = strchr(s,0);
- *tp++ = ch;
- *tp = 0;
- return(s);
- }
-
- strptr pastocstr(strptr ps)
- {
- byte b;
-
- b = *ps;
- memmove(ps,ps+1,b);
- ps[b] = '\0';
- return(ps);
- }
-
-
- /*
- ****************************************************************************
- ** Function : mid
- **
- ** Arguments : (char *) - string to store result in
- ** (char *) - string to extract from
- ** (int) - start position in source string
- ** (int) - length in bytes
- ** Returns : (char *) - a pointer to the destination string
- **
- ** This function attempts to extract a portion of the source string and
- ** place that portion in the destination string.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 01/06/90 1.0 SN Original Version
- ** 10/07/91 1.1 SN Used to return nothing, now returns
- ** pointer to destination
- **
- ****************************************************************************
- */
-
-
- char * mid(char *destination, char *source, int start, int length)
- {
- char *startOfDestination;
-
- source = source + start;
- startOfDestination = destination;
- while ((*destination++ = *source++) != '\0' && (--length)) continue;
-
- if (!length) *destination = '\0';
- return(startOfDestination);
- }
-
-
- /*
- ****************************************************************************
- ** Function : strgt
- **
- ** Arguments : (char *) - string1 is the string to test on
- ** (char *) - string2 is the string to compare against
- ** Returns : (int) - (0-False, 1-True)
- **
- ** This function attempts to compare string1 against string2 to see if
- ** string1 is greater than string2.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 07/10/91 1.0 SN First version
- **
- ****************************************************************************
- */
-
-
- int strgt(char *source1, char *source2)
- {
- return(strcmp(source1, source2) > 0);
- }
-
-
- /*
- ****************************************************************************
- ** Function : strlt
- **
- ** Arguments : (char *) - string1 is the string to test on
- ** (char *) - string2 is the string to compare against
- ** Returns : (int) - (0-False, 1-True)
- **
- ** This function attempts to compare string1 against string2 to see if
- ** string1 is less than string2.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 07/10/91 1.0 SN First version
- **
- ****************************************************************************
- */
-
-
- int strlt(char *source1, char *source2)
- {
- return(strcmp(source1, source2) < 0);
- }
-
-
- /*
- ****************************************************************************
- ** Function : strgte
- **
- ** Arguments : (char *) - string1 is the string to test on
- ** (char *) - string2 is the string to compare against
- ** Returns : (int) - (0-False, 1-True)
- **
- ** This function attempts to compare string1 against string2 to see if
- ** string1 is greater than or equal to string2.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 07/10/91 1.0 SN First version
- **
- ****************************************************************************
- */
-
-
- int strgte(char *source1, char *source2)
- {
- return(strcmp(source1, source2) >= 0);
- }
-
-
- /*
- ****************************************************************************
- ** Function : strlte
- **
- ** Arguments : (char *) - string1 is the string to test on
- ** (char *) - string2 is the string to compare against
- ** Returns : (int) - (0-False, 1-True)
- **
- ** This function attempts to compare string1 against string2 to see if
- ** string1 is less than or equal to string2.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 07/10/91 1.0 SN First version
- **
- ****************************************************************************
- */
-
-
- int strlte(char *source1, char *source2)
- {
- return(strcmp(source1, source2) <= 0);
- }
-
-
- /*
- ****************************************************************************
- ** Function : strne
- **
- ** Arguments : (char *) - string1 is the string to test on
- ** (char *) - string2 is the string to compare against
- ** Returns : (int) - (0-False, 1-True)
- **
- ** This function attempts to compare string1 against string2 to see if
- ** string1 is not equal to string2.
- **
- ** Date Version Who Description
- ** --------------------------------------------------------------------
- ** 07/10/91 1.0 SN First version
- **
- ****************************************************************************
- */
-
-
- int strne(char *source1, char *source2)
- {
- return(strcmp(source1, source2) != 0);
- }
-
-
- /**************************** END OF DB_STR.C *****************************/
-